package bdqn.com.cui.dao.impl;

import bdqn.com.cui.dao.ProductcatesDao;
import bdqn.com.cui.pojo.Productcates;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ProductcatesDaoimpl extends BaseDao implements ProductcatesDao {
    @Override
    public List<Productcates> fenleiselect1() {
        return null;
    }

    @Override
    public List<Productcates> fenleiselect2() {
        Connection conn=getconn();
        PreparedStatement preparedStatement = null;
        ResultSet resultSet=null;
        String sql="SELECT ID,p_name FROM product_cates WHERE grade=2";
        try {
            preparedStatement=conn.prepareStatement(sql);
            resultSet=preparedStatement.executeQuery();
            List<Productcates> list=new ArrayList();
            while (resultSet.next()){
                if (resultSet!=null){
                    Productcates productcates=new Productcates();
                    productcates.setID(resultSet.getInt(1));
                    productcates.setName(resultSet.getString(2));
                    list.add(productcates);
                }
            }
            return list;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            getclass(resultSet,preparedStatement,conn);
        }

    }

    @Override
    public List<Productcates> fenleiselect3() {
        Connection conn=getconn();
        PreparedStatement preparedStatement = null;
        ResultSet resultSet=null;
        String sql="SELECT ID,p_name FROM product_cates WHERE grade=3";
        try {
            preparedStatement=conn.prepareStatement(sql);
            resultSet=preparedStatement.executeQuery();
            List<Productcates> list=new ArrayList();
            while (resultSet.next()){
                if (resultSet!=null){
                    Productcates productcates=new Productcates();
                    productcates.setID(resultSet.getInt(1));
                    productcates.setName(resultSet.getString(2));
                    list.add(productcates);
                }
            }
            return list;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            getclass(resultSet,preparedStatement,conn);
        }
    }
}
